home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
pascal
/
3dlib30a.zip
/
CTM3D.INT
< prev
next >
Wrap
Text File
|
1994-03-10
|
10KB
|
167 lines
(******************************************************************************
* Ctm3d *
******************************************************************************)
Unit Ctm3d;
(*******************************************************************************
* Homogeneous Coordinates *
* ----------------------- *
* *
* Homogeneous coordinates allow transformations to be represented by *
* matrices. A 3x3 matrix is used for 2D transformations, and a 4x4 matrix*
* for 3D transformations. *
* *
* THIS MODULE IMPLEMENTS ONLY 3D TRANSFORMATIONS. *
* *
* in homogeneous coordination the point P(x,y,z) is represented as *
* P(w*x, w*y, w*z, w) for any scale factor w!=0. *
* in this module w == 1. *
* *
* Transformations: *
* 1. translation *
* [x, y, z] --> [x + Dx, y + Dy, z + Dz] *
* *
* ┌ ┐ *
* │1 0 0 0│ *
* T(Dx, Dy, Dz) = │0 1 0 0│ *
* │0 0 1 0│ *
* │Dx Dy Dz 1│ *
* └ ┘ *
* 2. scaling *
* [x, y, z] --> [Sx * x, Sy * y, Sz * z] *
* *
* ┌ ┐ *
* │Sx 0 0 0│ *
* S(Sx, Sy) = │0 Sy 0 0│ *
* │0 0 Sz 0│ *
* │0 0 0 1│ *
* └ ┘ *
* *
* 3. rotation *
* *
* a) Around the Z axis: *
* *
* [x, y, z] --> [x*cost - t*sint, x*sint + y*cost, z] *
* ┌ ┐ *
* │cost sint 0 0│ *
* Rz(t) = │-sint cost 0 0│ *
* │0 0 1 0│ *
* │0 0 0 1│ *
* └ ┘ *
* *
* b) Around the X axis: *
* *
* [x, y, z] --> [x, y*cost - z*sint, y*sint + z*cost] *
* ┌ ┐ *
* │1 0 0 0│ *
* Rx(t) = │0 cost sint 0│ *
* │0 -sint cost 0│ *
* │0 0 0 1│ *
* └ ┘ *
* *
* c) Around the Y axis: *
* *
* [x, y, z] --> [xcost + z*sint, y, z*cost - x*sint] *
* ┌ ┐ *
* │cost 0 -sint 0│ *
* Ry(t) = │0 1 0 0│ *
* │sint 0 cost 0│ *
* │0 0 0 1│ *
* └ ┘ *
* *
* transformation of the vector [x,y,z,1] by transformation matrix T is given *
* by the formula: *
* ┌ ┐ *
* [x', y', z', 1] = [x,y,z,1]│ T │ *
* └ ┘ *
* Optimizations: *
* The most general composition of R, S and T operations will produce a matrix*
* of the form: *
* ┌ ┐ *
* │r11 r12 r13 0│ *
* │r21 r22 r23 0│ *
* │r31 r32 r33 0│ *
* │tx ty tz 1│ *
* └ ┘ *
* The task of matrix multiplication can be simplified by *
* x' = x*r11 + y*r21 + z*r31 + tx *
* y' = x*r12 + y*r22 + z*r32 + ty *
* z' = x*r13 + y*r23 + z*r33 + tz *
* *
* *
* See also: *
* "Fundamentals of Interactive Computer Graphics" J.D FOLEY A.VAN DAM *
* Adison-Weslely ISBN 0-201-14468-9 pp 245-265 *
*******************************************************************************)
interface
uses
hdr3d
;
type
ctmPtr = ^ ctm;
ctm = object
r11, r12, r13 : real; { change to single if numeric processor is present }
r21, r22, r23 : real;
r31, r32, r33 : real;
tx, ty, tz : real;
constructor SetUnit; { set to the unit (I) matrix }
constructor Copy(var src : ctm); { construct from another }
procedure save(var dest : ctm);
procedure translate(Dx, Dy, Dz : real); { used to move .. }
procedure translateX(dx : real);
procedure translateY(dy : real);
procedure translateZ(dz : real); {